package com.lxb;

public class RemoveNthFromEnd {
    public static void main(String[] args) {

        ListNode head = new ListNode(1);

        ListNode first = new ListNode(2);
        head.next = first;

//        ListNode second = new ListNode(3);
//        first.next = second;
//
//        ListNode third = new ListNode(4);
//        second.next = third;
//
//        ListNode forth = new ListNode(5);
//        third.next = forth;

        int n = 2;
        ListNode cur = head;
        int len = 1;
        while(cur.next != null){
            len++;
            cur = cur.next;
        }

        ListNode cur1 = head;
        for (int i=1;i<len-n;i++){
            cur1 = cur1.next;
        }
        cur1.next = cur1.next.next;

        while(head != null){
            System.out.println(head.val);
            head = head.next;
        }


    }
}
